package lumis.search.lucene;

import java.io.IOException;
import java.util.HashSet;

import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;

/**
 * Filter that skip duplicate terms
 * @version $Revision: 5769 $ $Date: 2007-02-01 12:00:07 -0200 (Thu, 01 Feb 2007) $
 * @since 4.0.9
 */
public class UniqueTermFilter extends TokenFilter
{
	private HashSet<String> terms = new HashSet<String>();
	public UniqueTermFilter(TokenStream in)
	{
		super(in);
	}

	@Override
	public Token next() throws IOException
	{
		Token token = null;
		while (1==1)
		{
			token = input.next();
			if (token == null)
				break;
			if (!terms.add(token.termText()))
				continue;
			break;
		}
		return token;
 	}
}
